package com.jzhao.jpre.model.dao;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.jzhao.jpre.base.StringPublicDeal;
import com.jzhao.jpre.format.DataObjectMap;
import com.jzhao.jpre.format.DataObjectType;
import com.jzhao.jpre.model.PmsSearchOrg;
import com.jzhao.jpre.model.PmsSearchPath;
import com.jzhao.jpre.model.PospSysParam;
import com.jzhao.jpre.model.PospTransInfo;
import com.jzhao.jpre.model.PmsSearchMerchant;


public class PmsSearchOrgDao 
{
	protected JdbcTemplate jdbcTemplate;
	protected StringPublicDeal strPubDeal;

	public void setDataSource(DataSource dataSource) 
	{
		jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public void setStrPubDeal(StringPublicDeal strPubDeal) 
	{
		this.strPubDeal = strPubDeal;
	}
	class PmsOrgRowMapper implements RowMapper 
	{

		public Object mapRow(ResultSet rs, int rowNum) throws SQLException 
		{
			PmsSearchOrg psm = new PmsSearchOrg();
			psm.setBRNO(rs.getString("BRNO"));
			psm.setBR_NAME(rs.getString("BR_NAME"));
			return psm;
		}
	}
	
	public PmsSearchOrg selectOrg(String serialNo)
	{
		String sql="SELECT  a.SERIALNO, a.NAME "
			      +" FROM PMS_ORGANIZATION_INFO a, PMS_MERCHANT_INFO b "
			      +" WHERE a.ID = b.ORGID AND b.SERIALNO = '"+serialNo+"'";
			      
		return (PmsSearchOrg)jdbcTemplate.queryForObject(sql, new PmsOrgRowMapper());
	}
	
	public PmsSearchOrg selectOrgNew(String serialNo)
	{
		String sql="SELECT  a.ZONENO, a.ZONENAME "
			      +" FROM T_SYS_ZONE a, PMS_MERCHANT_INFO b "
			      +" WHERE a.ZONENO = b.ORGID AND b.SERIALNO = '"+serialNo+"'";
		
		System.out.println("sql==="+sql);    
		return (PmsSearchOrg)jdbcTemplate.queryForObject(sql, new PmsOrgRowMapper());
	}	
	
}